home *** CD-ROM | disk | FTP | other *** search
- package views
- {
- import flash.accessibility.*;
- import flash.debugger.*;
- import flash.display.*;
- import flash.errors.*;
- import flash.events.*;
- import flash.external.*;
- import flash.filters.*;
- import flash.geom.*;
- import flash.media.*;
- import flash.net.*;
- import flash.printing.*;
- import flash.profiler.*;
- import flash.system.*;
- import flash.text.*;
- import flash.ui.*;
- import flash.utils.*;
- import flash.xml.*;
- import mx.binding.*;
- import mx.containers.Canvas;
- import mx.controls.Image;
- import mx.core.UIComponentDescriptor;
- import mx.core.mx_internal;
- import mx.events.PropertyChangeEvent;
- import mx.managers.PopUpManager;
- import mx.styles.*;
-
- public class MyPrintJob extends Canvas
- {
- private static var _watcherSetupUtil:IWatcherSetupUtil;
-
- private var _bindings:Array;
-
- public var _bindingsByDestination:Object;
-
- [Bindable]
- private var _143903767printedImg:Image;
-
- [Bindable]
- private var _2138617268whichPage:String = "";
-
- [Bindable]
- private var _1796000984twoPages:Boolean = false;
-
- public var _bindingsBeginWithWord:Object;
-
- [Bindable]
- private var _859611628imageURL:String;
-
- private var _watchers:Array;
-
- private var _documentDescriptor_:UIComponentDescriptor;
-
- public function MyPrintJob()
- {
- _documentDescriptor_ = new UIComponentDescriptor({
- "type":Canvas,
- "propertiesFactory":function():Object
- {
- return {"childDescriptors":[new UIComponentDescriptor({
- "type":Image,
- "id":"printedImg",
- "events":{"init":"__printedImg_init"}
- })]};
- }
- });
- _1796000984twoPages = false;
- _2138617268whichPage = "";
- super();
- mx_internal::_document = this;
- }
-
- public static function set watcherSetupUtil(param1:IWatcherSetupUtil) : void
- {
- MyPrintJob._watcherSetupUtil = param1;
- }
-
- [Bindable(event="propertyChange")]
- public function get printedImg() : Image
- {
- return this._143903767printedImg;
- }
-
- public function set printedImg(param1:Image) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._143903767printedImg;
- if(_loc2_ !== param1)
- {
- this._143903767printedImg = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"printedImg",_loc2_,param1));
- }
- }
-
- public function set imageURL(param1:String) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._859611628imageURL;
- if(_loc2_ !== param1)
- {
- this._859611628imageURL = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"imageURL",_loc2_,param1));
- }
- }
-
- public function __printedImg_init(param1:Event) : void
- {
- imageInit(param1);
- }
-
- public function set whichPage(param1:String) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._2138617268whichPage;
- if(_loc2_ !== param1)
- {
- this._2138617268whichPage = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"whichPage",_loc2_,param1));
- }
- }
-
- private function _MyPrintJob_bindingsSetup() : void
- {
- var binding:Binding = null;
- if(!_bindings)
- {
- _bindings = [];
- }
- if(!_watchers)
- {
- _watchers = [];
- }
- binding = new Binding(this,function():Object
- {
- return "images/large/" + imageURL;
- },function(param1:Object):void
- {
- printedImg.source = param1;
- },"printedImg.source");
- _bindings[0] = binding;
- }
-
- [Bindable(event="propertyChange")]
- public function get twoPages() : Boolean
- {
- return this._1796000984twoPages;
- }
-
- private function imageInit(param1:Event) : void
- {
- twoPages = param1.target.contentWidth > param1.target.contentHeight ? true : false;
- param1.target.width = param1.target.contentWidth;
- param1.target.height = param1.target.contentHeight;
- param1.target.x = (param1.target.width - this.stage.width) / 2;
- param1.target.y = -(param1.target.height - this.stage.height) / 2;
- trace("final width " + param1.target.width + " height " + param1.target.height);
- }
-
- public function printPages() : void
- {
- if(twoPages)
- {
- printSelection();
- return;
- }
- doPrinting();
- }
-
- private function printSelection() : void
- {
- var _loc1_:PrintSelection = null;
- _loc1_ = PopUpManager.createPopUp(this,PrintSelection,true) as PrintSelection;
- _loc1_.x = (this.parent.width - _loc1_.width) / 2;
- _loc1_.y = (this.parent.height - _loc1_.height) / 2;
- _loc1_.oCreator = this;
- _loc1_.imageURL = this.imageURL;
- }
-
- public function set twoPages(param1:Boolean) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._1796000984twoPages;
- if(_loc2_ !== param1)
- {
- this._1796000984twoPages = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"twoPages",_loc2_,param1));
- }
- }
-
- private function _MyPrintJob_bindingExprs() : void
- {
- var _loc1_:* = undefined;
- _loc1_ = "images/large/" + imageURL;
- }
-
- [Bindable(event="propertyChange")]
- public function get imageURL() : String
- {
- return this._859611628imageURL;
- }
-
- [Bindable(event="propertyChange")]
- public function get whichPage() : String
- {
- return this._2138617268whichPage;
- }
-
- override public function initialize() : void
- {
- var target:MyPrintJob = null;
- var watcherSetupUtilClass:Object = null;
- mx_internal::setDocumentDescriptor(_documentDescriptor_);
- _MyPrintJob_bindingsSetup();
- target = this;
- if(_watcherSetupUtil == null)
- {
- watcherSetupUtilClass = getDefinitionByName("_views_MyPrintJobWatcherSetupUtil");
- watcherSetupUtilClass["init"](null);
- }
- _watcherSetupUtil.setup(this,function(param1:String):*
- {
- return target[param1];
- },_bindings,_watchers);
- super.initialize();
- }
-
- public function doPrinting() : void
- {
- var pj:PrintJob = null;
- var pagesToPrint:int = 0;
- var options:PrintJobOptions = null;
- var origWidth:int = 0;
- var origHeight:int = 0;
- var origRotation:Number = NaN;
- var rect:Rectangle = null;
- var pScaleX:Number = NaN;
- var pScaleY:Number = NaN;
- pj = new PrintJob();
- pagesToPrint = 0;
- options = new PrintJobOptions();
- options.printAsBitmap = true;
- origWidth = printedImg.width;
- origHeight = printedImg.height;
- origRotation = printedImg.rotation;
- rect = new Rectangle(0,0,origWidth,origHeight);
- if(pj.start())
- {
- if(PrintJobOrientation.LANDSCAPE == pj.orientation)
- {
- printedImg.rotation = -90;
- }
- trace("PrintJob " + pj.pageWidth + ", " + pj.pageHeight + " orientation " + pj.orientation);
- if(true == twoPages)
- {
- if(PrintJobOrientation.LANDSCAPE == pj.orientation)
- {
- pScaleX = pj.pageWidth / origHeight;
- pScaleY = pj.pageHeight / (origWidth / 2);
- }
- else
- {
- pScaleX = pj.pageWidth / (origWidth / 2);
- pScaleY = pj.pageHeight / origHeight;
- }
- }
- else if(PrintJobOrientation.LANDSCAPE == pj.orientation)
- {
- pScaleX = pj.pageWidth / origHeight;
- pScaleY = pj.pageHeight / origWidth;
- }
- else
- {
- pScaleX = pj.pageWidth / origWidth;
- pScaleY = pj.pageHeight / origHeight;
- }
- trace("pScaleX " + pScaleX + " pScaleY " + pScaleY);
- if(PrintJobOrientation.LANDSCAPE == pj.orientation)
- {
- if(pScaleX > pScaleY)
- {
- printedImg.scaleX = pScaleX;
- printedImg.scaleY = pScaleX;
- }
- else
- {
- printedImg.scaleX = pScaleY;
- printedImg.scaleY = pScaleY;
- }
- }
- else if(pScaleX < pScaleY)
- {
- printedImg.scaleX = pScaleX;
- printedImg.scaleY = pScaleX;
- }
- else
- {
- printedImg.scaleX = pScaleY;
- printedImg.scaleY = pScaleY;
- }
- printedImg.validateNow();
- trace("newWidth " + printedImg.width + " newHeight " + printedImg.height);
- try
- {
- if(twoPages)
- {
- if("left" == whichPage || "both" == whichPage)
- {
- rect.width = origWidth / 2;
- pj.addPage(printedImg,rect,options);
- pagesToPrint++;
- }
- if("right" == whichPage || "both" == whichPage)
- {
- rect.x = rect.width = origWidth / 2;
- pj.addPage(printedImg,rect,options);
- pagesToPrint++;
- }
- }
- else
- {
- pj.addPage(printedImg,rect,options);
- }
- }
- catch(err:Error)
- {
- trace("printJob error " + err.message);
- }
- if(pagesToPrint > 0)
- {
- pj.send();
- }
- trace("currentWidth:",origWidth);
- trace(printedImg.width,printedImg.height,printedImg.rotation);
- printedImg.width = origWidth;
- printedImg.height = origHeight;
- printedImg.rotation = origRotation;
- printedImg.scaleX = printedImg.scaleY = 1;
- printedImg.validateNow();
- trace("rescale");
- trace("origWidth:",origWidth);
- trace(printedImg.width,printedImg.height,printedImg.rotation);
- }
- else
- {
- trace("print job cancelled");
- }
- }
- }
- }
-
-